package com.maxlen.search.controller;

import com.maxlen.common.exception.ExceptionCode;
import com.maxlen.common.to.es.SkuEsModel;
import com.maxlen.common.utils.R;
import com.maxlen.search.service.ProductSaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/search")
public class ElasticSaveController {

    @Autowired
    private ProductSaveService productSaveService;

    // 上架商品
    @PostMapping("/save/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModelList){
        boolean b = false;
        try {
            b = productSaveService.productStatusUp(skuEsModelList);
        } catch (IOException e) {
            return R.error(ExceptionCode.PRODUCT_UP_EXCEPTION);
        }

        if(b){
            return R.ok();
        }else{
            return R.error(ExceptionCode.PRODUCT_UP_EXCEPTION);
        }
    }
}
